<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>

    if (true) {
        let a = 1
        console.log(a)
    }
    // 常量
    const PI =3.14
    const STR = "lisi"

    const arr = [1,2]
    console.log(...arr)
    const obj = {age:18}
    arr[0] = 3
    console.log(arr)
    obj.age = 10
    console.log(obj)

    // 数组解构
    let [a,b,c] = arr
    console.log(a)
    console.log(b)
    console.log(c)
    // 对象解构
    let {age:aage} = obj
    console.log(aage)

    // 函数
    function f() {
        return "12"
    }
    const fn = function () {
        console.log(this)
        return ()=>{
            console.log(this)
        }
    };
    const f3 =  fn.call(obj)
    f3()

    // 箭头函数
    const ff= ()=>{}
    const f1= (num1,num2)=>num1+num2
    const f2= num1=>num1*2


    let ary = [{
        id: 1,
        name: '张三'
    }, {
        id: 2,
        name: "李四"
    }];

    let find = ary.findIndex(item=>item.id===2);
    console.log(find)

    // 模板字符串 ``
    let aStr = `a${f()}
    a`
    console.log(aStr)

    //定义了父类
    class Father {
        constructor(x, y) {
            this.x = x;
            this.y = y;
        }
        sum() {
            console.log(this.x + this.y);
        }
    }

    class Son extends Father{

        constructor(a,b) {
            super(a,b);
            this.a = a
            this.b = b
        }

        subtract(){
            console.log(this.a-this.b)
        }
    }

    let son = new Son(1,2);
    son.sum()
    son.subtract();

    // 立即执行的箭头函数
        (()=>{
            fetch("https://api.apiopen.top/api/sentences")
                .then(resp=>{
                    return resp.json()
                }).then(res =>{
                    console.log(res)
            })
            // post
            fetch('https://api.apiopen.top/api/login', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({ account: '309324904@qq.com', password: "123456" })
            }).then(resp=>{
                return resp.json()
            }).then(res =>{
                console.log(res)
            })

        })()




</script>
</html>